//按渲染树递归调用ActionIn达到翻起来的效果

cc.Class({
    extends: cc.Component,

    properties: {

    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.appendAction(this.node)
        this.showAction(this.node,0)

    },
    
    appendAction(UInode){
        if(UInode.name.search("AnimationCancel") === -1 ){  //名字里包含AnimationCancel字符串的不执行动画
            if(UInode.getComponent(cc.Sprite)){    
                if(!UInode.getComponent('ActionIn') && UInode.active){
                    UInode.addComponent('ActionIn')
                }
            }
        }
            if(UInode.children && UInode.children.length>0 ){              
                for(let i=0;i<UInode.children.length;i++){
                    let child = UInode.children[i]
                        this.appendAction(child)
                }
            }else{
                return
            }
    },

    showAction(UInode,depth){
        if(UInode.parent){
            if(UInode.name.search("AnimationCancel") === -1 ){
                try{
                    if(UInode.getComponent(cc.Sprite)){
                            if(UInode.getComponent('ActionIn')){
                                UInode.getComponent('ActionIn').playAnime()
                            }else{
                                UInode.addComponent('ActionIn')
                                UInode.getComponent('ActionIn').playAnime()
                            }
                        depth++
                    }
                }catch(err){
                    cc.log(err)
                    cc.log(UInode)
                }
            }
        }
        if(UInode.children && UInode.children.length>0 ){              
            for(let i=0;i<UInode.children.length;i++){
                let child = UInode.children[i]
                let time = (depth) * 100 + i * 100
                setTimeout(()=>{
                        this.showAction(child,depth)
                    },time)
                }
        }else{
            return
        }

    }

    // update (dt) {},
});
